#pragma once
#include "Session.h"
#include <memory>
#include <map>
#include "MsgNode.h"
#include "const.h"
#include <queue>
#include <functional>
#include <mutex>
#include <condition_variable>
#include <thread>
class LogicNode;
class LogicSystem
{
public:
	static LogicSystem& GetInstance();
	~LogicSystem();
	void PostToLogic(std::shared_ptr<Session> session, std::shared_ptr<RecvNode> recv_node);
private:
	void RegisteredCallBack();
	void DealMsg();
	LogicSystem(const LogicSystem&) = delete;
	LogicSystem& operator=(const LogicSystem&) = delete;
	void HelloCallBack(std::shared_ptr<LogicNode>);
	LogicSystem();
	std::queue<std::shared_ptr<LogicNode>> _logic_queue;
	std::map<short, std::function<void(std::shared_ptr<LogicNode>)>> _callback_functions;
	std::mutex _mutex;
	std::condition_variable _consume;
	std::thread _work_thread;
	bool _b_stop;
};

class LogicNode 
{
public:
	LogicNode(std::shared_ptr<Session> session, std::shared_ptr<RecvNode> recv_node):
	_session(session),_recv_node(recv_node){}
	std::shared_ptr<Session> _session;
	std::shared_ptr<RecvNode> _recv_node;
};